//
//  StoreGoodsTypeCell.m
//  KYRR
//
//  Created by kuyuZJ on 2017/4/22.
//
//

#import "StoreGoodsTypeCell.h"

@interface StoreGoodsTypeCell ()

@property(nonatomic,strong) UILabel* labelForum;
@property(nonatomic,strong) UILabel* labelLine;

@property(nonatomic,strong) MGoodsType* entity;
@end

@implementation StoreGoodsTypeCell



-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
//        self.backgroundColor = [UIColor colorWithRed:222/255.f green:222/255.f blue:222/255.f alpha:1.0];
        [self.contentView addSubview:self.labelForum];
        [self.contentView addSubview:self.labelLine];
        
        NSArray<NSString*>* formats = @[@"H:|-leftEdge-[labelForum]-leftEdge-|", @"V:|-defEdge-[labelForum]-defEdge-|",
                                        @"H:|-defEdge-[labelLine]-defEdge-|", @"V:|-defEdge-[labelLine(==lineHeight)]-defEdge-|"];
        NSDictionary<NSString*,id>* metrics = @{ @"defEdge":@(0), @"leftEdge":@(10), @"topEdge":@(10), @"lineHeight":@(1.f)};
        NSDictionary<NSString*,id>* views = @{ @"labelForum":self.labelForum, @"labelLine":self.labelLine };
        [formats enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            NSLog( @"%@ %@",[self class],obj);
            NSArray<NSLayoutConstraint*>* constraints = [NSLayoutConstraint constraintsWithVisualFormat:obj options:0 metrics:metrics views:views];
            [self.contentView addConstraints:constraints];
        }];
    }
    return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    if(selected){
        self.backgroundColor = [UIColor whiteColor];
    }else{
        self.backgroundColor = [UIColor colorWithRed:245/255.f green:245/255.f blue:245/255.f alpha:1.0];
    }

    
    // Configure the view for the selected state
}

-(void)loadDataWithItem:(MGoodsType *)item isSelected:(BOOL)isSelected{
    if(item){
        _entity = item;
//        if(isSelected){
//            self.backgroundColor = [UIColor whiteColor];
//        }else{
//            self.backgroundColor = [UIColor colorWithRed:222/255.f green:222/255.f blue:222/255.f alpha:1.0];
//        }
        self.labelForum.text = self.entity.catename;
    }
}


#pragma mark ===================================================== property package

-(UILabel *)labelForum{
    if(!_labelForum){
        _labelForum = [[UILabel alloc]init];
        _labelForum.textAlignment = NSTextAlignmentCenter;
        _labelForum.numberOfLines = 2;
        _labelForum.font = [UIFont boldSystemFontOfSize:14.f];
        _labelForum.translatesAutoresizingMaskIntoConstraints = NO;
    }
    return _labelForum;
}

-(UILabel *)labelLine{
    if(!_labelLine){
        UILabel* empty = [[UILabel alloc]init];
        empty.backgroundColor = theme_line_color;
        empty.translatesAutoresizingMaskIntoConstraints = NO;
        _labelLine = empty;
    }
    return _labelLine;
}

@end
